package com.deneme.ozveri.activities;


import com.deneme.ozveri.adapters.OrderListAdapter;
import com.deneme.ozveri.application.OzveriMenuApplicationObject;
import com.deneme.ozveri.objects.MenuOrderItem;
import com.deneme.ozveri.objects.MenuOrderItemExtras;
import com.deneme.ozverimenu.R;

import android.app.Activity;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class OrderListActivity extends Activity {

	ListView orderlist;
	Button cleanAll;
	Button sendOrder;
	TextView totalPrice;
	OrderListAdapter mainAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.orders);
		orderlist = (ListView) findViewById(R.id.orders_list_listview);
		totalPrice = (TextView) findViewById(R.id.orders_total_txt);
		mainAdapter = new OrderListAdapter(getApplicationContext());
		if (OzveriMenuApplicationObject.orders.isEmpty()) {

		}
		else
		{
			orderlist.setAdapter(mainAdapter);
			mainAdapter.registerDataSetObserver(new DataSetObserver() {
				@Override
				public void onChanged() {
					calculateTotal();
					super.onChanged();
				}
			});
		}



		calculateTotal();
		super.onCreate(savedInstanceState);
	}

	private void calculateTotal(){
		int finalTotal = 0;
		for (int k = 0; k < OzveriMenuApplicationObject.orders.size(); k++) {
			MenuOrderItem currItem = OzveriMenuApplicationObject.orders.get(k);
			finalTotal += currItem.getOrderTotalPrice()*currItem.getOrderQuantity();				
		}
		totalPrice.setText(""+finalTotal*1.0/100.0);

	}

}
